package com.qf.sclg.controller;

import com.qf.sclg.entity.Pic;
import com.qf.sclg.result.ResponseData;
import com.qf.sclg.service.PicService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (Pic)表控制层
 *
 * @author makejava
 * @since 2021-10-13 10:42:26
 */
@RestController
@RequestMapping("pic")
public class PicController {
//自动实例化生成对象
// @Autowired在实例化过程中，impl会检查类是否实现service，通过类型注入
// @Resource只判断piervicecsimpl名字是否一致，通过名字注入
    @Autowired
    private PicService picService;
    @ApiOperation(value="通过状态和类型获取对应的图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "轮播/导航",dataType = "string",required = true),
            @ApiImplicitParam(name = "status",value = "0/1",dataType = "Integer",required = true)
    })
//    加入api（移动端），分辨不同端
    @GetMapping("/api/query/{type}/{status}")
    public ResponseData queryByType(@PathVariable("status") Integer status, @PathVariable("type") String type){
//        返回多个数据
//        ResponseData responseData = picService.queryByType(type,status);
        return picService.queryByType(type,status);
    }


    //    查询所有图片
    @ApiOperation(value="查询所有图片")
    @GetMapping("/all")
    public ResponseData queryByAll() {
      List<Pic> pics = picService.queryByAll();
      return new ResponseData("0","success",pics);
    }
    
}

